package com.gome.rb.factory;

import java.util.HashMap;
import java.util.List;
import java.util.Random;

import com.gome.rb.job.jobservice.RefundTaskService;
import com.gome.util.ClassUtils;

@SuppressWarnings("all")
public class RefundTaskFactory {
	
	private static HashMap<String, RefundTaskService> refundTaskServices = new HashMap<String, RefundTaskService>();

	public static RefundTaskService createTaskService(Class c) {
		RefundTaskService refundTaskService = null; // 定义一个类型的人类
		try {
			if (refundTaskServices.containsKey(c.getSimpleName())) {
				refundTaskService = refundTaskServices.get(c.getSimpleName());
			} else {
				refundTaskService = (RefundTaskService) Class.forName(c.getName()).newInstance();
				refundTaskServices.put(c.getSimpleName(), refundTaskService);
			}
		} catch (InstantiationException e) {
			//System.out.println("必须指定人种的颜色");
		} catch (IllegalAccessException e) { 
			//System.out.println("人种定义错误！");
		} catch (ClassNotFoundException e) { 
			//System.out.println("混蛋，你指定的人种找不到！");
		}
		return refundTaskService;
	}
	
	//女娲生气了，把一团泥巴塞到八卦炉，哎产生啥人种就啥人种
	public static RefundTaskService createTaskService(){
		RefundTaskService refundTaskService = null; // 定义一个类型的人类
	//首先是获得有多少个实现类，多少个人种
	List<Class> concreteHumanList =
	ClassUtils.getAllClassByInterface(RefundTaskService.class); //定义了多少人种
	//八卦炉自己开始想烧出什么人就什么人
	Random random = new Random();
	int rand = random.nextInt(concreteHumanList.size());
	refundTaskService = createTaskService(concreteHumanList.get(rand));
	return refundTaskService;
	}
//	
	
}
